package com.team1.system.librarystock.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.team1.common.annotation.Log;
import com.team1.common.core.controller.BaseController;
import com.team1.common.core.domain.AjaxResult;
import com.team1.common.enums.BusinessType;
import com.team1.system.librarystock.domain.LibraryStock;
import com.team1.system.librarystock.service.ILibraryStockService;
import com.team1.common.utils.poi.ExcelUtil;
import com.team1.common.core.page.TableDataInfo;

/**
 * 图书库存管理Controller
 * 
 * @author hyy
 * @date 2023-04-16
 */
@RestController
@RequestMapping("/librarysystem/librarystock")
public class LibraryStockController extends BaseController
{
    @Autowired
    private ILibraryStockService libraryStockService;

    /**
     * 查询图书库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarystock:list')")
    @GetMapping("/list")
    public TableDataInfo list(LibraryStock libraryStock)
    {
        startPage();
        List<LibraryStock> list = libraryStockService.selectLibraryStockList(libraryStock);
        return getDataTable(list);
    }

    /**
     * 导出图书库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarystock:export')")
    @Log(title = "图书库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LibraryStock libraryStock)
    {
        List<LibraryStock> list = libraryStockService.selectLibraryStockList(libraryStock);
        ExcelUtil<LibraryStock> util = new ExcelUtil<LibraryStock>(LibraryStock.class);
        util.exportExcel(response, list, "图书库存管理数据");
    }

    /**
     * 获取图书库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarystock:query')")
    @GetMapping(value = "/{stockId}")
    public AjaxResult getInfo(@PathVariable("stockId") Long stockId)
    {
        return success(libraryStockService.selectLibraryStockByStockId(stockId));
    }

    /**
     * 新增图书库存管理
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarystock:add')")
    @Log(title = "图书库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LibraryStock libraryStock)
    {
        return toAjax(libraryStockService.insertLibraryStock(libraryStock));
    }

    /**
     * 修改图书库存管理
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarystock:edit')")
    @Log(title = "图书库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LibraryStock libraryStock)
    {
        return toAjax(libraryStockService.updateLibraryStock(libraryStock));
    }

    /**
     * 删除图书库存管理
     */
    @PreAuthorize("@ss.hasPermi('librarysystem:librarystock:remove')")
    @Log(title = "图书库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockIds}")
    public AjaxResult remove(@PathVariable Long[] stockIds)
    {
        return toAjax(libraryStockService.deleteLibraryStockByStockIds(stockIds));
    }
}
